package cst.neu.yuejian_31.model;

import cst.neu.yuejian_31.bean.ClubStateBean;
import cst.neu.yuejian_31.iface.ClubCollectStateIface;
import cst.neu.yuejian_31.iface.ClubCollectStateListener;
import cst.neu.yuejian_31.service.ClubCollectStateService;
import cst.neu.yuejian_31.Common.Constant;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/10/25.
 */

public class ClubCollectStateModel implements ClubCollectStateIface {
    private Retrofit retrofit;
    public ClubCollectStateModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getClubState(String userId, String clubId, final ClubCollectStateListener clubCollectStateListener) {
        ClubCollectStateService clubCollectStateService=retrofit.create(ClubCollectStateService.class);
        Call<ClubStateBean>call=
                clubCollectStateService.getClubState(userId,clubId);
        call.enqueue(new Callback<ClubStateBean>() {
            @Override
            public void onResponse(Call<ClubStateBean> call, Response<ClubStateBean> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    clubCollectStateListener.onSuccess(response.body());
                }else {
                    clubCollectStateListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<ClubStateBean> call, Throwable t) {
                clubCollectStateListener.onFail(t.toString());
            }
        });

    }
}
